/*
 *	Copyright 2011 ja4cli
 *
 *	Licensed under the Apache License, Version 2.0 (the "License");
 *	you may not use this file except in compliance with the License.
 *	You may obtain a copy of the License at
 *
 *		http://www.apache.org/licenses/LICENSE-2.0
 *
 *	Unless required by applicable law or agreed to in writing, software
 *	distributed under the License is distributed on an "AS IS" BASIS,
 *	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *	See the License for the specific language governing permissions and
 *	limitations under the License.
 */
package org.skarby.ja4cli.configuration;

import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.skarby.ja4cli.internal.Guard;

/**
 * Value object for holding state of a boolean alias.<p/>
 * 
 * @author askarby
 * @see BooleanConfig
 */
public class BooleanAlias {
	private final String text;
	private final boolean value;

	/**
	 * Constructs a new alias for a boolean.
	 * @param text the String / text to consider equivalent to the supplied value parameter, may <b>not</b> be <code>null</code>.
	 * @param value the value of the alias.
	 */
	public BooleanAlias(String text, boolean value) {
		Guard.isNull(text);
		this.text = text;
		this.value = value;
	}

	/**
	 * Retrieves the text of the alias.<p/>
	 * 
	 * The alias is character data, that should be considered to be the boolean value, such as (ie.):
	 * <ul>
	 * <li>"true"</li>
	 * <li>"yes"</li>
	 * </ul>
	 * given that the value is <code>true</code>.
	 * 
	 * @return the text of the alias.
	 */
	public String getText() {
		return text;
	}
	
	/**
	 * The value of the alias.
	 * @return the value of the alias.
	 */
	public boolean getValue() {
		return value;
	}
	
	/**
	 * Determines if the passed String argument matches the text of the alias,
	 * disregarding any whitespace.
	 * @param text the text to determin if matching the text of the alias.
	 * @return <code>true</code> if the text matches the alias, <code>false</code> if not.
	 */
	public boolean matches(String text) {
		if (text != null) {
			text = text.trim();
		}
		return this.text.equalsIgnoreCase(text);
	}
	
	@Override
	public boolean equals(Object obj) {
		return EqualsBuilder.reflectionEquals(this, obj);
	}
	
	@Override
	public int hashCode() {
		return HashCodeBuilder.reflectionHashCode(this, true);
	}
}
